package org.xx.sipahi.controllers;

import java.util.Date;

import static org.xx.armory.commons.MapUtils.getDate;
import static org.xx.armory.commons.MapUtils.getInteger;
import static org.xx.armory.commons.MapUtils.getString;
import static org.xx.armory.commons.RequestUtils.fixEndDate;
import static org.xx.armory.commons.RequestUtils.fixStartDate;
import static org.xx.armory.spring5.mvc.ModelUtils.parseArgs;

public final class NoticeSearchForm {
    private final Integer categoryId;
    private final String title;
    private final String keyword;
    private final String updater;
    private final Date startDate;
    private final Date endDate;

    public NoticeSearchForm(
            String args
    ) {
        final var argMap = parseArgs(args, "categoryId", "title", "keyword", "updater", "startDate", "endDate");
        this.categoryId = getInteger(argMap, "categoryId");
        this.title = getString(argMap, "title");
        this.keyword = getString(argMap, "keyword");
        this.updater = getString(argMap, "updater");
        this.startDate = fixStartDate(getDate(argMap, "startDate", null));
        this.endDate = fixEndDate(getDate(argMap, "endDate", null));
    }

    public Integer getCategoryId() {
        return this.categoryId;
    }

    public String getTitle() {
        return title;
    }

    public String getKeyword() {
        return keyword;
    }

    public String getUpdater() {
        return updater;
    }

    public Date getStartDate() {
        return startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    @Override
    public String toString() {
        return "NoticeSearchForm(" +
                "categoryId=" + this.categoryId +
                ",title='" + this.title + '\'' +
                ",keyword='" + this.keyword + '\'' +
                ",updater='" + this.updater + '\'' +
                ",startDate=" + this.startDate +
                ",endDate=" + this.endDate +
                ')';
    }
}
